/*
 * Yabumi, a 2d scrolling shoot-em-up game.
 * Copyright (C) 2003 Gemma Teruaki <terugen@yabumi.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
 */

#include <SDL.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include "../taskmanager.h"
#include "../sprite.h"
#include "../video.h"
#include "../util.h"
#include "game.h"
#include "title.h"

static enum {__title, __game} title_flag = __title;
static void Handle_Event();

task Scene_Title(_option *optv)
{
  Sprite_Init();
  Handle_Event();

  SDL_Surface *image;
  /* Draw Title */
  int i;
  i = (optv->count / -5) % 2;
  image = Sprite_Title[i];
  Sprite_Add_Ex(DISPLAY_CENTER_X, DISPLAY_CENTER_Y - 80, Z_ORDER_D2, image);
  image = Sprite_Title_Instruct[0];
  Sprite_Add_Ex(DISPLAY_CENTER_X, DISPLAY_CENTER_Y + 100, Z_ORDER_D2, image);
  i = (optv->count / -20) % 2;
  image = Sprite_Title_Press[i];
  Sprite_Add_Ex(DISPLAY_CENTER_X, DISPLAY_CENTER_Y, Z_ORDER_D2, image);
  Video_Sprites_Draw();

  if (title_flag == __game) {
    title_flag = __title;
    Sprite_Free();
    Task_Free();
    Task_Add(Scene_Game, NULL, NULL, INFINITY_COUNT);
  };
}

static void Handle_Event()
{
  if (Key_Register.space == 1) {
    Key_Register.space = 0;
    title_flag = __game;
  };
  if (Key_Register.up == true);
  if (Key_Register.down == true);
  if (Key_Register.left == true);
  if (Key_Register.right == true);

  if (Key_Register.z == true) Key_Register.z = false;
  if (Key_Register.x == true) Key_Register.x = false;
  if (Key_Register.c == true) Key_Register.c = false;
  if (Key_Register.p == true) Key_Register.p = false;
  if (Key_Register.q == true) {
    Key_Register.q = false;
    exit(0);
  };
}
